home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / game / shoot / Orbit_src.lha / Orbit / source / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-04  |  3.5 KB  |  151 lines

  1. /*
  2.     Amiga port by Oliver Gantert
  3.  
  4.     27.04.2000 - fixed some compiler warnings
  5. */
  6. /*
  7.  
  8. ORBIT, a freeware space combat simulator
  9. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  24.  
  25. */
  26.  
  27. #include "orbit.h"
  28.  
  29. /*
  30.  *  Handle the mouse
  31.  */
  32.  
  33. int oldx, oldy;
  34.  
  35. static void Mouse (int x, int y)
  36. /*
  37.  *  Mouse motion callback
  38.  */
  39. {
  40.   /* Don't bother if position hasn't changed */
  41.   if ( (x == oldx) && (y == oldy) ) return;
  42.  
  43.   mouse.x = x;
  44.   mouse.y = y;
  45. }
  46.  
  47. static void MouseActive (int x, int y)
  48. /*
  49.  *  Mouse motion callback
  50.  */
  51. {
  52.   PlayerFires();
  53.  
  54.   /* Don't bother if position hasn't changed */
  55.   if ( (x == oldx) && (y == oldy) ) return;
  56.  
  57.   mouse.x = x;
  58.   mouse.y = y;
  59. }
  60.  
  61. void InitMouse()
  62. /*
  63.  *  Initialize the mouse
  64.  */
  65. {
  66.   glutPassiveMotionFunc (Mouse);
  67.   glutMotionFunc (MouseActive);
  68.  
  69.   if (mouse_control)
  70.   {
  71.     glutSetCursor (GLUT_CURSOR_NONE);
  72.     oldx = ScreenWidth / 2;
  73.     oldy = ScreenHeight/ 2;
  74.     glutWarpPointer (oldx, oldy); 
  75.     mouse.x = oldx; 
  76.     mouse.y = oldy;
  77.   }
  78. }
  79.  
  80. void DoMouse()
  81. /*
  82.  *  Check for mouse movement
  83.  */
  84. {
  85.   /* Not if we're dead */ 
  86.   if ( (state == STATE_DEAD1) || (state == STATE_DEAD2) ) return; 
  87.  
  88.   if (mouse.x > oldx) mouse.right = mouse.x - oldx;
  89.   if (mouse.x < oldx) mouse.left  = oldx - mouse.x;
  90.   if (mouse.y > oldy) mouse.up    = mouse.y - oldy;
  91.   if (mouse.y < oldy) mouse.down  = oldy - mouse.y;
  92.  
  93.   #ifndef AMIGA
  94.   if (mouse.flipx)
  95.   {
  96.     if (mouse.left ) player.move_right = 0.1 * (double) mouse.left;
  97.     if (mouse.right) player.move_left  = 0.1 * (double) mouse.right;
  98.   }
  99.   else
  100.   {
  101.     if (mouse.left ) player.move_left  = 0.1 * (double) mouse.left;
  102.     if (mouse.right) player.move_right = 0.1 * (double) mouse.right;
  103.   }
  104.  
  105.   if (mouse.flipy)
  106.   {
  107.     if (mouse.up   ) player.move_down  = 0.1 * (double) mouse.up;
  108.     if (mouse.down ) player.move_up    = 0.1 * (double) mouse.down;
  109.   }
  110.   else
  111.   {
  112.     if (mouse.up   ) player.move_up    = 0.1 * (double) mouse.up;
  113.     if (mouse.down ) player.move_down  = 0.1 * (double) mouse.down;
  114.   }
  115.   #else
  116.   if (mouse.flipx)
  117.   {
  118.     if (mouse.left ) player.move_right = 0.01 * (double) mouse.left;
  119.     if (mouse.right) player.move_left  = 0.01 * (double) mouse.right;
  120.   }
  121.   else
  122.   {
  123.     if (mouse.left ) player.move_left  = 0.01 * (double) mouse.left;
  124.     if (mouse.right) player.move_right = 0.01 * (double) mouse.right;
  125.   }
  126.  
  127.   if (mouse.flipy)
  128.   {
  129.     if (mouse.up   ) player.move_down  = 0.01 * (double) mouse.up;
  130.     if (mouse.down ) player.move_up    = 0.01 * (double) mouse.down;
  131.   }
  132.   else
  133.   {
  134.     if (mouse.up   ) player.move_up    = 0.01 * (double) mouse.up;
  135.     if (mouse.down ) player.move_down  = 0.01 * (double) mouse.down;
  136.   }
  137.   #endif /* AMIGA */
  138.  
  139.   mouse.left  = 0;
  140.   mouse.right = 0;
  141.   mouse.up    = 0;
  142.   mouse.down  = 0;
  143.  
  144.   oldx = ScreenWidth / 2;
  145.   oldy = ScreenHeight/ 2;
  146.   glutWarpPointer (oldx, oldy);
  147.  
  148.   mouse.x = oldx;
  149.   mouse.y = oldy;
  150. }
  151.